< previous page page_292 next page >

Page 292
Synchronizing the List Box
Of course, what would be even nicer on this screen is the ability to click the DataList control and have the data in the controls update to reflect the current name selected. You can do this with just a few lines of code.
EXERCISE
Add Code to the MouseUp( ) Event of the DataList
1. Double-click the DataList control.
2. Select the MouseUp() event from the Procedures combo box.
3. Type in the following code in this event:
Private Sub dlstEmp_MouseUp(Button As Integer, _
Shift As Integer, _
x As Single, _
y As Single)
datEmployees.Recordset.Bookmark = dlstEmp.SelectedItem
End Sub
analysis.gifEach time the user clicks an entry in the list box, you need to tell the data control to move to that row. To accomplish this, you can use the SelectedItem property of the DataList control, which is a bookmark of the Recordset in the data control. As such, you can take this value and give it to the Bookmark property of the Recordset object of the data control. This forces the data control to move to that record, thereby updating all the bound controls on the form.

Data-bound Grid Control
The data-bound grid control (DataGrid) is a new grid that works with the ADO data control only. Its not the same grid that shipped with Visual Basic 5. Be careful that you select the Microsoft DataGrid Control 6.0 (OLEDB) option and not the Microsoft Data Bound Grid Control 5.0 option, which can be used only with Jet data controls. (Note that you might not have the version 5 grid control if you dont have Visual Basic 5 on your system.)
Grids are great for displaying multiple columns of data that otherwise might not fit in a list box. Also, a list box cant display data in neat columns without using a Windows API call, and even then the data can grow too large for a column and push the next column farther to the right. With a grid, you can have each column display within a specified width, and even have it wrap the text within the column, if you want. Figure 14.4 shows what the DataGrid control looks like in the toolbox.

 
< previous page page_292 next page >

If you like this book, buy it!